﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects;
using DemoObject;
using DemoObject.EntityMappers;
using System.Text.RegularExpressions;
using System.IO;
public partial class Module_Video_Controls_VideoPlayer : System.Web.UI.UserControl
{
    public string VideoTextId { get; set; }
    public TblVideo itemvdieo;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["VideoTextId"] != null)
            {
                VideoTextId = Request["VideoTextId"];
            }
            itemvdieo = TblVideoRepository.CreateInstant().SelectOne(VideoTextId);
            if (itemvdieo != null)
            {
                itemvdieo.Views++;
                TblVideoRepository.CreateInstant().Update(itemvdieo);
                if (itemvdieo.IsInternal)
                {
                    TblTypeCode _TblTypeCode = TblTypeCodeRepository.CreateInstant().SelectOne((Guid)itemvdieo.VideoTypeCodeId);
                    VideoSource.Text = _TblTypeCode.Value.Replace("[width/]", "700").Replace("[height/]", "400").Replace("[source/]", itemvdieo.VideoSource);
                }
                else
                {
                    //string patternH = "/height=\"[0-9]*\"/";
                    //string patternW = "/width=\"[0-9]*\"/";
                    //VideoSource.Text = Regex.Replace(Regex.Replace(itemvdieo.VideoSource, patternW, "width='700'"), patternH, "width='400'");
                    string patternw = "[\\s]*width=[\"'\\s]([^\"'a-zA-Z#\\s>])+\"[\"'\\s]*";
                    string patternh = "[\\s]*height=[\"'\\s]([^\"'a-zA-Z#\\s>])+\"[\"'\\s]*";
                    string inputW = " width='700' "; // cai an truyen vo
                    string inputH = " height='400' "; // cai an truyen vo
                    VideoSource.Text = Regex.Replace(Regex.Replace(itemvdieo.VideoSource, patternh, inputH, RegexOptions.IgnorePatternWhitespace), patternw, inputW);
                }
                SetTitle(itemvdieo);
            }
        }
    }
    void SetTitle(TblVideo _item)
    {
        string title = _item.Name;
        string description = _item.Name;
        string keywords = _item.Name;
        MasterPage _page = this.Page.Master;
        HTT.Utility.WebUtility.SetPage(title, description, keywords, _page);
    }
}
